package com.wangzhixuan.commons.easemob;

import org.apache.log4j.Logger;

import com.wangzhixuan.commons.easemob.service.TalkDataService;
import com.wangzhixuan.commons.easemob.service.impl.TalkDataServiceImpl;
import com.wangzhixuan.commons.easemob.service.impl.TalkHttpServiceImplApache;

/**
 * 环信SDK 入口类 实现单例模式
 * 
 * @author 15338
 *
 */
public class Entry {
	private Logger logger = Logger.getLogger(this.getClass());
	public static final String INVAILID_CONTEXT_MSG = "Context is null or has not been initialized.";
	private static Entry entry = null;
	private TalkDataService service;

	private Entry() {
	}

	/**
	 * 懒汉单例
	 * 
	 * @return
	 */
	public static Entry getInstance() {
		if (null == entry) {
			entry = new Entry();
		}
		return entry;
	}

	public TalkDataService getTalkApi() {
		if (null == entry) {
			logger.error(INVAILID_CONTEXT_MSG);
			throw new RuntimeException(INVAILID_CONTEXT_MSG);
		}
		if (null == this.service) {
			this.service = new TalkDataServiceImpl(new TalkHttpServiceImplApache());
		}

		return this.service;
	}
}
